package com.link.base.base.receivable.controller;


import com.link.base.base.receivable.model.PayClct;
import com.link.base.base.receivable.service.PayClctService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 汇款制器，用来处理汇款相关信息
 * @author unknown
 * @date unknown
 * @comments 回款
 */
@Controller
@RequestMapping("/link/payClct")
public class PayClctController extends BasicController<PayClct> {

    @Resource
    private PayClctService payClctService;

    @Override
    public BasicService<PayClct> getBasicService() throws Exception {
        return payClctService;
    }

    /**
     * 预处理：存在父子级联，所以强制父Id不能为空
     */
    @Override
    public void beforQueryAllOrExample(PayClct entity, HttpServletRequest request) throws Exception {


        if (null != entity.getId()) {
            entity.setReceivableId(0L);
        } else {
            entity.setReceivableId(entity.getId());
        }
    }


    @RequestMapping(value = "/attachmentUpdate")
    @ResponseBody
    public Map<String, Object> attachmentUpdate(@JsonParam PayClct entity, HttpSession session,
                                                HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            payClctService.attachmentUpdate(entity);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

}
